package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.OrderSetting;
import com.itheima.health.service.OrderSettingService;
import com.itheima.health.utils.POIUtils;
import com.itheima.health.vo.DataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author 山外小王
 * @Description
 * @Date 2024/04/17/15:45
 */
@RestController
@RequestMapping("/ordersetting")
public class OrderSettingController {
    @Autowired
    private OrderSettingService orderSettingService;
    @Autowired
    private POIUtils poiUtils;

    @PostMapping("/upload")
    public Result upload (MultipartFile excelFile) throws IOException {
        //读取Excel文件
        try {
            List<OrderSetting> orderSettingList = poiUtils.readExcel(excelFile);
            if (orderSettingList != null && orderSettingList.size()>0) {
                orderSettingService.add(orderSettingList);
            }
        } catch (IOException e) {
            e.printStackTrace();
            return new Result(false,"批量导入预约设置数据失败");
        }
        return new Result(true,"批量导入预约设置数据成功");
    }

    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMonth(String year,String month){
        List<DataVO> data = orderSettingService.getOrderSettingByMonth(year,month);
        return new Result(true, MessageConst.GET_ORDERSETTING_SUCCESS,data);
    }

    @PostMapping("/editNumberByDate")
    public Result editNumberByDate(@RequestBody OrderSetting orderSetting){
        orderSettingService.editNumberByDate(orderSetting);
        return new Result(true,MessageConst.ORDERSETTING_SUCCESS);
    }
}
